package com.umeox.watch.moto.chat.db

import android.os.Parcel
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.Index
import androidx.room.PrimaryKey

/**
 * Created by Rambo 2021/8/18
 * Describe:
 */
@Entity(tableName = "chat_info", indices = arrayOf(Index(value = ["id", "msgId", "fuid", "tuid"])))

data class ChatMessage(
    @PrimaryKey(autoGenerate = true)
    var id: Long = 0,
    var msgId: String = "",
    var fuid: String = "",//发送消息的用户ID
    var tuid: String = "",//接受消息的用户ID
    var type: Int = 0,//消息类型 0:私聊 1:群聊
    var msgType: Int = -1,//消息内容类型, 0: 文本，1: 语聊，2：聊天表情, 3：图片，31：PTT语聊
    var msgTime: Long = 0,//消息发送时间，unix时间戳,精确到毫秒
    /**
     * 微聊消息内容
     * 当chatType为0时，内容为文本
     * 当chatType为1、3时，内容为文件URL地址
     * 当chatType为2时，内容为表情数字标记符
     */
    var msgBody: String = "",
    /**
     * 文件下载保存到本地的路径
     */
    var filePath: String? = null,
    var length: Int = 0,//文件长度
    var state: Int = 0,//消息状态
    var unRead: Int = 0,//未读标记，0表示已读，1表示未读

) : Parcelable {

    @Ignore
    var selected: Boolean = false

    constructor(parcel: Parcel) : this() {
        this.id = parcel.readLong()
        this.msgId = parcel.readString().toString()
        this.fuid = parcel.readString().toString()
        this.tuid = parcel.readString().toString()
        this.type = parcel.readInt()
        this.msgType = parcel.readInt()
        this.msgTime = parcel.readLong()
        this.msgBody = parcel.readString().toString()
        this.filePath = parcel.readString()
        this.length = parcel.readInt()
        this.state = parcel.readInt()
        this.unRead = parcel.readInt()
    }


    override fun writeToParcel(dest: Parcel, flags: Int) {
        dest.writeLong(id)
        dest.writeString(msgId)
        dest.writeString(fuid)
        dest.writeString(tuid)
        dest.writeInt(type)
        dest.writeInt(msgType)
        dest.writeString(msgBody)
        dest.writeString(filePath)
        dest.writeInt(length)
        dest.writeInt(state)
        dest.writeInt(unRead)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<ChatMessage> {
        override fun createFromParcel(source: Parcel): ChatMessage {
            return ChatMessage(source)
        }

        override fun newArray(size: Int): Array<ChatMessage?> {
            return arrayOfNulls(size)
        }

    }

}
